package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.StReportPort;
import com.ruoyi.system.api.service.IStReportPortService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 报告备件
 *
 * @ClassName AcceptanceReportController.java
 * @date 2020/3/9 8:41 上午
 * @author yzg
 */
@Api(tags="报告备件")
@RestController
@RequestMapping("/api/cc/report/port/")
public class ReportPortController extends BaseController {

    @Autowired
    private IStReportPortService reportPortService;

    private static final Logger log = LoggerFactory.getLogger(ReportPortController.class);
    /**
     *  添加 1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息
     *
     * @param reportPort
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020-03-03 14:00
     */
    @RepeatSubmit
    @Log(title = "添加报告", businessType = BusinessType.INSERT)
    @PostMapping("addReportPort")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "添加 1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息", httpMethod = "POST", notes = "添加 1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> addReportPort(@RequestBody StReportPort reportPort){
        try {
            return reportPortService.addReportPort(reportPort);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  添加服务报告备件信息
     *
     * @param reportPort
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020-03-03 14:00
     */
    @Log(title = "添加服务报告备件信息", businessType = BusinessType.INSERT)
    @PostMapping("addFieldServiceReportPort")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "添加服务报告备件信息", httpMethod = "POST", notes = "添加服务报告备件信息")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> addFieldServiceReportPort(@RequestBody StReportPort reportPort){
        try {
            return reportPortService.addFieldServiceReportPort(reportPort);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  移除1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息
     *
     * @param enginnerId 工程师ID
     * @param reportPortId 备件表主键ID
     * @return com.ruoyi.system.api.ResponseWithData
     * @author yzg
     * @date 2020-03-03 15:02
     */
    @RepeatSubmit
    @Log(title = "删除报告", businessType = BusinessType.DELETE)
    @GetMapping("removeReportPort")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "移除1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息", httpMethod = "GET", notes = "移除1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "备件表主键ID", name = "reportPortId", required = true, dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "CC备件主键ID", name = "pid", required = true, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData removeReportPort(@RequestParam Long enginnerId, @RequestParam Long reportPortId, @RequestParam (value = "pid", required = false)String pid){
        try {
            return reportPortService.removeReportPort(enginnerId, reportPortId,pid);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     *  移除安装质量报告备件
     *
     * @param  id
     * @param
     * @return com.ruoyi.system.api.ResponseWithData
     * @author yzg
     * @date 2020-03-03 15:02
     */
    @Log(title = "移除安装质量报告", businessType = BusinessType.DELETE)
    @GetMapping("removeReportPortByInstallation")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "移除安装质量报告", httpMethod = "GET", notes = "移除1、安装质量报告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "安装质量报告ID", name = "id", required = true, dataType = "Long", paramType = "query")

    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData removeReportPortByInstallation(@RequestParam Long id){
        try {
            int rmoveid= reportPortService.removeReportPortByInstallation(id);
            return new ResponseWithData().success().msg("删除成功").code(200);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  移除服务报告备件信息
     *
     * @param enginnerId 工程师ID
     * @param reportPortId 备件表主键ID
     * @return com.ruoyi.system.api.ResponseWithData
     * @author yzg
     * @date 2020-03-03 15:02
     */
    @Log(title = "移除服务报告备件信息", businessType = BusinessType.DELETE)
    @GetMapping("removeFieldServiceReportPort")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "移除服务报告备件信息", httpMethod = "GET", notes = "移除服务报告备件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, dataType = "Long", paramType = "query"),
            @ApiImplicitParam(value = "备件表主键ID", name = "reportPortId", required = true, dataType = "Long", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData removeFieldServiceReportPort(@RequestParam Long enginnerId, @RequestParam Long reportPortId){
        try {
            return reportPortService.removeFieldServiceReportPort(enginnerId, reportPortId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查询1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息
     *
     * @param serviceNo serviceNo
     * @param helpId 报告辅助id
     * @param type 查询类型 1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020-03-03 15:56
     */
    @GetMapping("selectReportPorts")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息", httpMethod = "GET", notes = "查询1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "报告辅助id", name = "helpId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "查询类型 1、服务报告备件信息, 2、电话解决报告备件信息", name = "type", required = false, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectReportPorts(@RequestParam(value="serviceNo",required=true) String serviceNo,
                                                 @RequestParam(value="helpId",required=true) String helpId,
                                                 @RequestParam(value="type",required=false) String type) {
        try {
            return reportPortService.selectReportPorts(serviceNo, helpId, type);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    @GetMapping("selectServiceReportPorts")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息", httpMethod = "GET", notes = "查询1、服务报告 2、电话解决报告 3、Error Report 4、Hot Account Report等报告备件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "报告辅助id", name = "helpId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "查询类型 1、服务报告备件信息, 2、电话解决报告备件信息", name = "type", required = false, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectServiceReportPorts(@RequestParam(value="serviceNo",required=true) String serviceNo,
                                                 @RequestParam(value="helpId",required=true) String helpId,
                                                 @RequestParam(value="type",required=false) String type) {
        try {
            return reportPortService.selectServiceReportPorts(serviceNo, helpId, type);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    /**
     *  查询本地备件使用数量
     *
     * @param partNumber
     * @return com.ruoyi.system.api.ResponseWithData
     * @author yzg
     * @date 2020/4/7 3:20 下午
     */
    @GetMapping("selectPartQty")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "", httpMethod = "GET", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "备件号", name = "partNumber", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "辅助id", name = "helpId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师id", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData selectPartQty(@RequestParam("partNumber") String partNumber,
                                                     @RequestParam("serviceNo") String serviceNo,
                                                     @RequestParam("helpId") String helpId,
                                                     @RequestParam("enginnerId") String enginnerId) {
        try {
            return reportPortService.selectPartQty(partNumber, serviceNo, helpId, enginnerId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  根据备件号查询备件单价、备件名称
     *
     * @param partCode	备件号
     * @return com.ruoyi.system.api.ResponseWithData
     * @author yzg
     * @date 2020/4/10 1:43 下午
     */
    @GetMapping("selectPriceByPartcode")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "", httpMethod = "GET", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "备件号", name = "partCode", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData selectPriceByPartcode(@RequestParam("partCode") String partCode) {
        try {
            return reportPortService.selectPriceByPartcode(partCode);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

}
